#include "rss.h"

#include <dirent.h>
#include <sys/types.h>
#include <string.h>

#include <vector>

using std::vector;
using std::string;

const string xmlPath = "../../../data/xml/";
const string ripepagePath = "ripepage.dat";
const string offsetPath = "offset.dat";

void readAllFiles(const string& path, vector<string>& files){
    DIR *dir;
    struct dirent *ent;
    if((dir = opendir(path.c_str())) != nullptr){
        while((ent = readdir(dir)) != nullptr){
            if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")){
                continue;
            }
            files.push_back(xmlPath + ent->d_name);
            /* cout << files.back() << endl; */
        }
    }
}

int main(){
    RSS rss(4000);

    vector<string> files;
    readAllFiles(xmlPath, files);

    for(auto& file: files){
        rss.read(file);
    }
    rss.store(ripepagePath, offsetPath);
    
}
